#!/bin/bash

# =============================================================================
# School-AIGC 快速API测试脚本
# 
# 用途：快速验证 Stable Diffusion WebUI API 的基础连接和核心功能
# 时间：约1-2分钟完成
# =============================================================================

API_BASE_URL="http://27860.agent-ai.cn:40800"
TIMEOUT=10

# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m'

echo -e "${BLUE}===========================================${NC}"
echo -e "${BLUE}School-AIGC 快速API测试${NC}"
echo -e "${BLUE}API Base URL: $API_BASE_URL${NC}"
echo -e "${BLUE}===========================================${NC}\n"

# 快速测试函数
quick_test() {
    local method="$1"
    local endpoint="$2"
    local description="$3"
    
    echo -n "测试 $description ... "
    
    if [ "$method" = "GET" ]; then
        response=$(curl -s -w '%{http_code}' --connect-timeout $TIMEOUT "${API_BASE_URL}${endpoint}" 2>/dev/null)
    else
        response=$(curl -s -w '%{http_code}' --connect-timeout $TIMEOUT -X POST "${API_BASE_URL}${endpoint}" 2>/dev/null)
    fi
    
    http_code="${response: -3}"
    
    if [ "$http_code" = "200" ]; then
        echo -e "${GREEN}✓ 通过${NC} (HTTP $http_code)"
        return 0
    else
        echo -e "${RED}✗ 失败${NC} (HTTP $http_code)"
        return 1
    fi
}

# 执行快速测试
echo -e "${YELLOW}[1] 基础连接测试${NC}"
quick_test "GET" "/" "根路径访问"
quick_test "GET" "/info" "API信息"

echo -e "\n${YELLOW}[2] 核心API测试${NC}"
quick_test "GET" "/sdapi/v1/sd-models" "SD模型列表"
quick_test "GET" "/sdapi/v1/samplers" "采样器列表"
quick_test "GET" "/sdapi/v1/upscalers" "放大器列表"
quick_test "GET" "/sdapi/v1/progress" "进度查询"

echo -e "\n${YELLOW}[3] 扩展功能测试${NC}"
quick_test "GET" "/controlnet/version" "ControlNet版本"
quick_test "GET" "/sdapi/v1/loras" "LoRA模型"

echo -e "\n${YELLOW}[4] 系统状态测试${NC}"
quick_test "GET" "/sdapi/v1/options" "系统配置"
quick_test "GET" "/sdapi/v1/memory" "内存信息"

echo -e "\n${BLUE}===========================================${NC}"
echo -e "${GREEN}快速测试完成！${NC}"
echo -e "${BLUE}如需完整测试，请运行: ./scripts/test-api.sh${NC}"
echo -e "${BLUE}===========================================${NC}" 